home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / WindowColors / WindowColors.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.7 KB  |  167 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        WindowColors.c
  3.  
  4.     Contains:    This application displays the default window colors        
  5.                 stored in the System's 'wctb' resource.  Note that    
  6.                 this app is 7.0 only, since it only recognizes the 7.0
  7.                 version of the resource
  8.  
  9.     Written by: Edgar Lee    
  10.  
  11.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  12.  
  13.                 You may incorporate this Apple sample source code into your program(s) without
  14.                 restriction. This Apple sample source code has been provided "AS IS" and the
  15.                 responsibility for its operation is yours. You are not permitted to redistribute
  16.                 this Apple sample source code as "Apple sample source code" after having made
  17.                 changes. If you're going to re-distribute the source, we require that you make
  18.                 it clear in the source that the code was descended from Apple sample source
  19.                 code, but that you've made changes.
  20.  
  21.     Change History (most recent first):
  22.                 8/6/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  23.                 
  24.  
  25. */
  26.  
  27. #include <Resources.h>
  28. #include <Dialogs.h>
  29. #include <Fonts.h>
  30.  
  31. /* Constant Declarations */
  32.  
  33. #define    WWIDTH        375
  34. #define    WHEIGHT        155
  35.  
  36. #define WLEFT        (((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - WWIDTH) / 2)
  37. #define WTOP        (((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - WHEIGHT) / 2)
  38.  
  39. /* Global Variable Definitions */
  40.  
  41. #define    TOTALWINCOLORS    13
  42.  
  43. CTabHandle    gWindowCTable;
  44.  
  45. Str255    gTitles[TOTALWINCOLORS] =
  46. {
  47.     "\pContent", "\pFrame", "\pText", "\pHilite",
  48.     "\pTitleBar", "\pHiliteLight", "\pHiliteDark", "\pTitleBarLight",
  49.     "\pTitleBarDark", "\pDialogLight", "\pDialogDark", "\pTingeLight",
  50.     "\pTingeDark"
  51. };
  52.  
  53.  
  54. void initMac();
  55. void createWindow();
  56. void drawWindowColors();
  57. void doEventLoop();
  58.  
  59. void main (void)
  60. {
  61.     initMac();
  62.     
  63.     createWindow();
  64.     
  65.     doEventLoop();
  66. }
  67.  
  68. void initMac()
  69. {
  70.     MaxApplZone();
  71.  
  72.     InitGraf( &(qd.thePort) );
  73.     InitFonts();
  74.     InitWindows();
  75.     InitMenus();
  76.     TEInit();
  77.     InitDialogs( nil );
  78.     InitCursor();
  79.     FlushEvents( 0, everyEvent );
  80. }
  81.  
  82. void createWindow()
  83. {
  84.     Rect        rect;
  85.     WindowPtr    window;
  86.     
  87.     SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  88.     window = NewCWindow( 0L, &rect, "\pDefault Window Colors", true, documentProc,
  89.                             (WindowPtr)-1L, true, 0L );                        
  90.     SetPort( window );
  91.     
  92.     TextFont( kFontIDGeneva );
  93.     TextSize( 9 );
  94.     TextMode( srcCopy );
  95.     
  96.     gWindowCTable = (CTabHandle)NewHandle( sizeof( ColorTable )
  97.                     + ((TOTALWINCOLORS - 1) * sizeof( ColorSpec )));
  98. }
  99.  
  100. void drawWindowColors()
  101. {
  102.     int            i;
  103.     int            col, row;
  104.     Rect        rect;
  105.         
  106.     if ((gWindowCTable = (CTabHandle)GetResource( 'wctb', 0 )) != nil)
  107.     {
  108.         for (i = 0; i < TOTALWINCOLORS; i++)
  109.         {
  110.             col = 20 + ((i % 5) * 68);
  111.             row = 25 + ((i / 5) * 45);
  112.             
  113.             SetRect( &rect, col, row, col + 60, row + 20 );
  114.             RGBForeColor( &(**gWindowCTable).ctTable[i].rgb );
  115.             PaintRect( &rect ); 
  116.             
  117.             InsetRect( &rect, -2, -2 );
  118.             ForeColor( blackColor );
  119.             FrameRect( &rect );
  120.             
  121.             MoveTo( rect.left, rect.top - 3 );
  122.             DrawString( gTitles[i] );
  123.         }
  124.     }
  125. }
  126.  
  127. void doEventLoop()
  128. {
  129.     EventRecord anEvent;
  130.     WindowPtr   evtWind;
  131.     short       clickArea;
  132.     Rect        screenRect;
  133.  
  134.     for (;;)
  135.     {
  136.         if (WaitNextEvent( everyEvent, &anEvent, 0, nil ))
  137.         {
  138.             if (anEvent.what == mouseDown)
  139.             {
  140.                 clickArea = FindWindow( anEvent.where, &evtWind );
  141.                 
  142.                 if (clickArea == inDrag)
  143.                 {
  144.                     screenRect = (**GetGrayRgn ()).rgnBBox;
  145.                     DragWindow( evtWind, anEvent.where, &screenRect );
  146.                 }
  147.                 else if (clickArea == inContent)
  148.                 {
  149.                     if (evtWind != FrontWindow())
  150.                         SelectWindow( evtWind );
  151.                 }
  152.                 else if (clickArea == inGoAway)
  153.                     if (TrackGoAway( evtWind, anEvent.where ))
  154.                         return;
  155.             }
  156.             else if (anEvent.what == updateEvt)
  157.             {
  158.                 evtWind = (WindowPtr)anEvent.message;    
  159.                 SetPort( evtWind );
  160.                 
  161.                 BeginUpdate( evtWind );
  162.                 drawWindowColors();
  163.                 EndUpdate (evtWind);
  164.             }
  165.         }
  166.     }
  167. }